package com.ruoyi.project.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ruoyi.project.domain.entity.Project;
import com.ruoyi.project.domain.entity.ProjectParticipan;
import com.ruoyi.project.domain.query.ProjectParticipanQuery;
import com.ruoyi.project.domain.query.ProjectQuery;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface ProjectParticipanMapper extends BaseMapper<ProjectParticipan> {
    List<ProjectParticipan> getList(ProjectParticipanQuery query);


    @Select("SELECT p.* \n" +
            "FROM project_participan p\n" +
            "JOIN (\n" +
            "    SELECT participan_name, MAX(id) AS min_id\n" +
            "    FROM project_participan\n" +
            "    WHERE post_id = #{postId}\n" +
            "    GROUP BY participan_name\n" +
            ") tmp ON p.participan_name = tmp.participan_name AND p.id = tmp.min_id;")
    List<ProjectParticipan> getSaleRole(Long postId);

    @Select("SELECT p.* \n" +
            "FROM project_participan p\n" +
            "JOIN (\n" +
            "    SELECT participan_name, MAX(id) AS min_id\n" +
            "    FROM project_participan\n" +
            "    WHERE post_id = #{postId}\n" +
            "      AND project_no LIKE '%XS%'\n" +
            "    GROUP BY participan_name\n" +
            ") tmp ON p.participan_name = tmp.participan_name AND p.id = tmp.min_id;")
    List<ProjectParticipan> getSaleRoleXS(Long postId);


}
